/*
 * PBBThread.java
 *
 * Created on May 19, 2007, 5:22 PM
 *  This will be the basis of all protienBoxBot Threads.  Just adds some basic functionality and gui support
 *  to the basic thread class.  Gui support will basically include error and basic function logging for 
 *  the debugging of the program.  
 *
 *Copyright 2007-2008 Jon W Huss III

   Licensed under the Apache License, Version 2.0 (the "License");
   you may not use this file except in compliance with the License.
   You may obtain a copy of the License at

       http://www.apache.org/licenses/LICENSE-2.0

   Unless required by applicable law or agreed to in writing, software
   distributed under the License is distributed on an "AS IS" BASIS,
   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
   See the License for the specific language governing permissions and
   limitations under the License.
 *
 */

package proteinboxbot;


import java.io.*;
import java.util.*;
import java.security.*;
import java.util.zip.*;

//Window Imports
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
import proteinboxbot.*;


/**
 *
 * @author Jon Huss
 */
public abstract class PBBThread extends Thread {
    
    //This is the constant representing the standard rest time in milliseconds for a
    //thread - used to make sure threads yield to other threads and for pausing operations.
    public static final int REST_TIME = 500;
    
    protected boolean killMe; //set this true to stop the thread (assuming proper
        //implimentation in pbbThreadRun method.  
    protected boolean pauseMe; //set this to true to pause this thread's operation
        //effectively causes this thread to sleep'
    
    private Object syncPauseKill;  //Used as a thread lock mechanism to avoid conflicting threads.
    
    /** Creates a new instance of PBBThread */
    public PBBThread() {
        killMe = false;
        pauseMe = false;
        syncPauseKill = new Object();
        
    }
    
    public void pauseThread() {
        synchronized(syncPauseKill) {
            pauseMe = true;
        }
    }
    
    public void unpauseThread() {
        synchronized(syncPauseKill) {
            pauseMe = false;
        }
    }
    
    public void killThread() {
        synchronized(syncPauseKill) {
            killMe = true;
        }
    }
    
    public void run(){
        //The start of the thread - this calls a method common to all threads that serves as the starting
        //point of the thread.
        
        this.pbbThreadRun();
        
    }
    
    abstract void pbbThreadRun();
    
}
